//
//  RootTabViewController.m
//  test
//
//  Created by apple on 16/3/25.
//  Copyright © 2016年 ibendi. All rights reserved.
//

#import "RootTabViewController.h"
#import "MyViewController.h"


#define TabbarVC    @"vc"
#define TabbarTitle @"title"
#define TabbarImage @"image"
#define TabbarSelectedImage @"selectedImage"


@interface RootTabViewController ()

@end

@implementation RootTabViewController

-(NSArray *)tabarItemArray
{
    if (!_tabarItemArray) {
        _tabarItemArray = @[@{TabbarTitle:@"首页",
                              TabbarImage:@"icon-me-normal",
                              TabbarSelectedImage:@"icon-me-press",
                              TabbarVC:@"ZYMainViewController"
                              },
                            @{TabbarTitle:@"聊天",
                              TabbarImage:@"icon-discover-normal",
                              TabbarSelectedImage:@"icon-discover-press",
                              TabbarVC:@"NewsViewController"
                              },
                             @{TabbarTitle:@"地址",
                               TabbarImage:@"icon-address list-normal",
                               TabbarSelectedImage:@"icon-address list-press",
                               TabbarVC:@"MyViewController"
                               },
                            ];
    }
    return _tabarItemArray;
}
- (void)viewDidLoad {
    
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    
    NSMutableArray *vcArray = [[NSMutableArray alloc] init];
    [self.tabarItemArray enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        Class clazz = NSClassFromString(self.tabarItemArray[idx][TabbarVC]);
        UIViewController *vc = [[clazz alloc] init];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:vc];
        nav.navigationBar.barTintColor = [UIColor mainColor];
        [self setUpTabbarItemWithController:nav
                              andItemImgStr:self.tabarItemArray[idx][TabbarImage]
                              andItemSelImg:self.tabarItemArray[idx][TabbarSelectedImage]
                                    andTitl:self.tabarItemArray[idx][TabbarTitle]
                                     andTag:900+idx];
        [vcArray addObject:nav];
    }];
    self.viewControllers = [NSArray arrayWithArray:vcArray];
    self.tabBar.barStyle = UIBarStyleDefault;

}

//修改tabbarItem 的属性
-(void)setUpTabbarItemWithController:(UIViewController *)aviewController andItemImgStr:(NSString *)imgStr andItemSelImg:(NSString *)selImgeStr andTitl:(NSString *)title andTag:(NSInteger )tage
{
    aviewController.tabBarItem.tag = tage;
    aviewController.tabBarItem.title = title;
    aviewController.tabBarItem.image = [[UIImage imageNamed:imgStr] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    aviewController.tabBarItem.selectedImage = [[UIImage imageNamed:selImgeStr] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    
    [aviewController.tabBarItem setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14.0],NSForegroundColorAttributeName:[UIColor mainColor]} forState:UIControlStateSelected]; //更改选中的的字体颜色
    
    [aviewController.tabBarItem setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14.0],NSForegroundColorAttributeName : [UIColor colorWithRed:163.00/255.00 green:163.00/255.00 blue:163.00/255.00 alpha:1]} forState:UIControlStateNormal]; // 正常的颜色
//    [[UITabBarItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont systemFontOfSize:14.0],NSForegroundColorAttributeName:[UIColor grayColor]} forState:UIControlStateSelected];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
